import router from '../router'
import axios from 'axios'

/**
 * 网络请求配置
 */
axios.defaults.baseURL = 'http://resonlei.top:7777'

axios.interceptors.request.use(function (config) {
  const token = localStorage.getItem('accessToken')
  if (!token) return config
  config.headers.Authorization = token
  return config
})

axios.interceptors.response.use(res => {
  if (res.data.statusCode === 401 && res.data.message === '用户信息验证失败') {
    router.push('/login')
  }
  return res
})

export default axios
